﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineBookStoreModel;
using System.Net.Mail;
using System.Net;

public partial class UserControls_FeedbackContentControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

            String id = Request.QueryString["FeedID"];
            if (id != null)
            {
                FeedBack feed = DataAccess.getFeedbackContent(id);
                TextBoxSubject.Text = feed.Subject;
                TextBoxContent.Text = feed.Content;
                TextBoxFirstName.Text = feed.FirstName + " " + feed.LastName;
                TextBoxEmail.Text = feed.Email;
            }

    }
    protected void ButtonDelete_Click(object sender, EventArgs e)
    {
        String id = Request.QueryString["FeedID"];
        if (id != null)
        {
            DataAccess.deleteFeedback(id);
            LabelResult0.Text = "Delete successfully.!";
            Response.Redirect("~/FeedbackAdmin.aspx");
        }
    }
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        String fromAddress = "conghoatranit@gmail.com";
        String toAddress = TextBoxEmail.Text;
        String subject = TextBoxSubject.Text;
        String body = TextBoxReplyContent.Text;
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, "conghoaz");
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);

        LabelResult.Text = "Email was send successful.!";

    }
    protected void ButtonReset_Click(object sender, EventArgs e)
    {
        TextBoxReplyContent.Text = "";
    }
}